package com.ycsj.goldmedalnewconcept.fragment;

import io.rong.imkit.RongIM;
import io.rong.imkit.RongIM.GroupInfoProvider;
import io.rong.imkit.RongIM.UserInfoProvider;
import io.rong.imlib.model.Group;
import io.rong.imlib.model.UserInfo;

import java.io.IOException;
import java.util.ArrayList;

import org.apache.http.conn.ssl.SSLSocketFactory;

import se.emilsjolander.stickylistheaders.StickyListHeadersAdapter;
import se.emilsjolander.stickylistheaders.StickyListHeadersListView;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.FragmentTransaction;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.view.animation.LinearInterpolator;
import android.view.animation.RotateAnimation;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.google.gson.Gson;
import com.squareup.okhttp.Call;
import com.squareup.okhttp.Callback;
import com.squareup.okhttp.FormEncodingBuilder;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.Response;
import com.squareup.picasso.Picasso;
import com.ycsj.goldmedalnewconcept.activity.MineConversationInfo;
import com.ycsj.goldmedalnewconcept.activity.UserInfoActivity;
import com.ycsj.goldmedalnewconcept.bean.AddressListresp;
import com.ycsj.goldmedalnewconcept.bean.ConversationListResq;
import com.ycsj.goldmedalnewconcept.bean.friendInfo;
import com.ycsj.goldmedalnewconcept.bean.groupInfo;
import com.ycsj.goldmedalnewconcept.bean.AddressListresp.friendListDetail;
import com.ycsj.goldmedalnewconcept.bean.AddressListresp.groupListDetail;
import com.ycsj.goldmedalnewconcept.constant.ConfigConstant;
import com.ycsj.goldmedalnewconcept.constant.Constant;
import com.ycsj.goldmedalnewconcept.constant.NetConstant;
import com.ycsj.goldmedalnewconcept.utils.SPUtil;
import com.ycsj.goldmedalnewconcept.utils.SPUtils;
import com.ycsj.goldmedalnewconcept.utils.Utils;
import com.ycsj.goldmedalnewconcept.R;

//我的伙伴
@SuppressLint("ClickableViewAccessibility")
public class ClassConversationFragment extends BaseFragment {
	private int grouplist_count = 0;
	private Activity ctx;
	private int state;
	// 定义header的四种状态和当前状态
	private static final int NONE = 0;
	private static final int PULL = 1;
	private static final int RELEASE = 2;
	private static final int REFRESHING = 3;
	private ImageView arrow;
	private ProgressBar refreshing;
	private TextView tip;
	private TextView lastUpdate;
	private int headerContentInitialHeight;
	private int headerContentHeight;
	private RotateAnimation animation;
	private RotateAnimation reverseAnimation;
	private RelativeLayout rl_lv_header;
	private boolean isRecorded;
	private int startY;
	private int scrollState;
	// 区分PULL和RELEASE的距离的大小
	private static final int SPACE = 20;

	private RelativeLayout progressBar;
	private static final String TAG = "ClassConversationFragment";
	private StickyListHeadersListView lv_process_list;
	// 获得好友列表
	private String path = NetConstant.FRIENDLIST;
	public ArrayList<friendInfo> friendlist = new ArrayList<friendInfo>();
	public ArrayList<UserInfo> UserList = new ArrayList<UserInfo>();
	public ArrayList<Group> GroupList = new ArrayList<Group>();
	private String account;
	private String disableGroup;

	public static ClassConversationFragment newInstance() {
		ClassConversationFragment collectFragment = new ClassConversationFragment();
		return collectFragment;
	}

	@Override
	public void onAttach(Activity activity) {
		super.onAttach(activity);
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	}

	@SuppressLint("ClickableViewAccessibility")
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {

		ctx = this.getActivity();

		View view = inflater.inflate(R.layout.fragment_classconversation,
				container, false);
		SPUtils.put(getActivity(), ConfigConstant.CURRENTFRAGMENT, TAG);

		account = SPUtil.getString(getActivity(), "account", "");
		disableGroup = SPUtil.getString(getActivity(), "disableGroup", "");

		lv_process_list = (StickyListHeadersListView) view
				.findViewById(R.id.lv_process_list);
		progressBar = (RelativeLayout) view.findViewById(R.id.progressBar);
		rl_lv_header = (RelativeLayout) view.findViewById(R.id.rl_lv_header);
		arrow = (ImageView) view.findViewById(R.id.arrow);
		tip = (TextView) view.findViewById(R.id.tip);
		lastUpdate = (TextView) view.findViewById(R.id.lastUpdate);
		refreshing = (ProgressBar) view.findViewById(R.id.refreshing);
		headerContentHeight = rl_lv_header.getMeasuredHeight();

		setActionBarTitle(view);
		// Log.e("test", SPUtils.getString(getActivity(),
		// ConfigConstant.IMTOKEN));
		// connect("B36pCG11LImqEpu4n70Wei75KxfWYG+yQTUevpxn5RVnTJFeDFjtvBZ4WzzY4UzQxUIm6aasunSb1ACB8HWmS14dO/zhgmzS");
		// if("".equals(SPUtils.getString(getActivity(),
		// "Friendlistjson"))||SPUtils.getBoolean(getActivity(),
		// "RongIMNeedRefresh")){
		// OkHttpClient mOkHttpClient = new OkHttpClient();
		// mOkHttpClient.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
		// FormEncodingBuilder builder = new FormEncodingBuilder();
		// builder.add("userid",SPUtils.getString(getActivity(),
		// ConfigConstant.USERNAME));
		// builder.add("usertoken", SPUtils.getString(getActivity(),
		// ConfigConstant.USERTOKEN));
		// Request request = new Request.Builder()
		// .url(path)
		// .post(builder.build()).build();
		// mOkHttpClient.newCall(request).enqueue(callBackFriendlist);
		OkHttpClient mOkHttpClient = new OkHttpClient();
		// 创建一个Request
		final Request request = new Request.Builder().url(
				Constant.ycsj_count_MessageCenter + "?type=13&c="
						+ SPUtil.getString(getActivity(), "account", "")
						+ "&role="
						+ SPUtil.getString(getActivity(), "role", "")
						+ "&platform=2")
		// .url("http://pm.moregolden.com/ycsj_count/MessageCenter?type=13&c="+SPUtil.getString(getActivity(),
		// "account", "")+"&role="+SPUtil.getString(getActivity(), "role",
		// "")+"&platform=2")
				.build();
		// new call13355556665
		Call call = mOkHttpClient.newCall(request);
		call.enqueue(callBackFriendlist);

		lv_process_list.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					final int position, long id) {
				UserList.add(new UserInfo(friendlist.get(position).friend,
						friendlist.get(position).friend_name, Uri
								.parse(friendlist.get(position).friend_headimg)));


				if (position == 0) {

					Intent intent = new Intent(getActivity(),
							UserInfoActivity.class);
					intent.putExtra("c", UserList.get(0).getUserId());
					intent.putExtra("role",
							SPUtil.getString(getActivity(), "role", ""));
					startActivity(intent);

				} else if (position >= 1 && position <= grouplist_count) {
					if (RongIM.getInstance() != null)
						RongIM.getInstance().startGroupChat(getActivity(),
								friendlist.get(position).friend,
								friendlist.get(position).friend_name);
					SPUtils.put(getActivity(), "clickGroupid",
							friendlist.get(position).friend);
					SPUtils.put(getActivity(), "clickGroupname",
							friendlist.get(position).friend_name);
					SPUtils.put(getActivity(), "clickGroupicon",
							friendlist.get(position).friend_headimg);

					RongIM.getInstance().setCurrentUserInfo(
							UserList.get(position));
					SPUtils.put(getActivity(), "tagetUsername",
							friendlist.get(position).friend_name);
					// Toast.makeText(getActivity(),
					// friendlist.get(position).friend_name, 0).show();
					SPUtils.put(getActivity(), "onUserPortraitClickid",
							friendlist.get(position).friend);

				} else {
					if (RongIM.getInstance() != null)

						RongIM.getInstance().startPrivateChat(getActivity(),
								friendlist.get(position).friend,
								friendlist.get(position).friend_name);
					SPUtil.putString(ctx, "clickRole",
							friendlist.get(position).friend_type);
					SPUtil.putString(ctx, "clickUserid",
							friendlist.get(position).friend);
					SPUtils.put(getActivity(), "tagetUsername",
							friendlist.get(position).friend_name);
					SPUtils.put(getActivity(), "onUserPortraitClickid",
							friendlist.get(position).friend);

				}
			}
		});

		if (!SPUtils.getBoolean(getActivity(), ConfigConstant.IS_LOGIN_ON)) {

			FragmentTransaction ft = getActivity().getSupportFragmentManager()
					.beginTransaction();
			ClassConversationNotloginFragment wf = new ClassConversationNotloginFragment();
			ft.replace(R.id.center_layout, wf);
			ft.addToBackStack(null);
			ft.commit();

		}

		return view;

	}

	@Override
	public void onViewCreated(View view, Bundle savedInstanceState) {
		super.onViewCreated(view, savedInstanceState);
		// initViews(view);
		Log.e("test_class", "Friendlistjson=Friendlistjson");
	}

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
	}

	private void initViews(View view) {

	}

	@Override
	public void onDestroy() {
		super.onDestroy();
	}

	@Override
	public void onSaveInstanceState(Bundle outState) {
		super.onSaveInstanceState(outState);
	}

	@Override
	public String getFragmentName() {
		return TAG;
	}

	Handler handler = new Handler();
	private AddressListresp mConversationListResq = new AddressListresp();
	Callback callBackFriendlist = new Callback() {

		@Override
		public void onResponse(Response arg0) throws IOException {
			String json = arg0.body().string();
			// 使用Gson把json解析成对象
			// 1 得到gson对象
			if (getActivity() != null) {

				SPUtils.put(getActivity(), "Friendlistjson", json);
			}
			Log.e("test", json);

			Gson gson = new Gson();

			mConversationListResq = gson.fromJson(json, AddressListresp.class);
			if (!friendlist.isEmpty()) {

				friendlist.removeAll(friendlist);
			}

			friendlist.add(
					0,
					new friendInfo(SPUtil.getString(ctx, "account", ""), SPUtil
							.getString(ctx, "icon", ""), SPUtil.getString(ctx,
							"name", ""), SPUtil.getString(ctx, "role", "")));

			if (mConversationListResq.groupList != null) {
				grouplist_count = mConversationListResq.groupList.size();
				for (groupListDetail groupInfo : mConversationListResq.groupList) {

					friendlist.add(1, new friendInfo(groupInfo.groupId,
							groupInfo.groupIcon, groupInfo.groupName));
					GroupList
							.add(new Group(groupInfo.groupId,
									groupInfo.groupName, Uri
											.parse(groupInfo.groupIcon)));

				}
			}
			if (mConversationListResq.friendList != null) {

				for (friendListDetail friendInfo : mConversationListResq.friendList) {

					friendlist.add(new friendInfo(friendInfo.USER_ID,
							friendInfo.HEADIMG, friendInfo.NAME,
							friendInfo.ROLE));

				}
			}
			handler.postDelayed(new Runnable() {

				@Override
				public void run() {
					// TODO Auto-generated method stub

					lv_process_list.setAdapter(new MyAdapter());


					for (friendInfo friendInfo : friendlist) {
						UserList.add(new UserInfo(friendInfo.friend,
								friendInfo.friend_name, Uri
										.parse(friendInfo.friend_headimg)));
					}
					for (UserInfo userInfoRefresh : UserList) {

						RongIM.getInstance().refreshUserInfoCache(
								userInfoRefresh);
					}

					RongIM.setGroupInfoProvider(new GroupInfoProvider() {

						@Override
						public Group getGroupInfo(String arg0) {
							for (int i = 0; i < GroupList.size(); i++) {
								if (GroupList.get(i).getId().equals(arg0)) {
									// Log.e("test",
									return GroupList.get(i);

								}
							}
							return null;
						}
					}, true);

					RongIM.setUserInfoProvider(new UserInfoProvider() {

						@Override
						public UserInfo getUserInfo(String userId) {
							for (int i = 0; i < UserList.size(); i++) {
								if (UserList.get(i).getUserId().equals(userId)) {
									// Log.e("test",
									// UserList.get(i).getName()+"---="+i);
									return UserList.get(i);
								}
							}
							return null;
						}
					}, true);
					if (getActivity() != null) {

						SPUtils.put(getActivity(), "RongIMNeedRefresh", false);
					}
					progressBar.setVisibility(progressBar.GONE);

				}
			}, 0);
		}

		@Override
		public void onFailure(Request arg0, IOException arg1) {
			// TODO Auto-generated method stub

		}
	};

	private TextView mTitle;
	private RelativeLayout mBack;

	class MyAdapter extends BaseAdapter implements StickyListHeadersAdapter {

		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return friendlist.size();
		}

		@Override
		public Object getItem(int position) {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public long getItemId(int position) {
			// TODO Auto-generated method stub
			return 0;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			ViewHolder vh = null;

			if (convertView == null) {
				convertView = View.inflate(parent.getContext(),
						R.layout.item_conversationlist, null);
				vh = new ViewHolder();
				vh.friend_name = (TextView) convertView
						.findViewById(R.id.tv_friend_name);
				vh.friend = (TextView) convertView.findViewById(R.id.tv_friend);
				vh.iv_friend_headimg = (ImageView) convertView
						.findViewById(R.id.iv_friend_headimg);
				vh.tv_teacher = (TextView) convertView
						.findViewById(R.id.tv_teacher);
				// vh.iv_grammar_second_bg = (ImageView)
				// convertView.findViewById(R.id.iv_grammar_second_bg);
				convertView.setTag(vh);
			} else {
				vh = (ViewHolder) convertView.getTag();
			}
			vh.friend_name.setText(friendlist.get(position).friend_name);

			vh.friend.setText(friendlist.get(position).friend);
			if ("0".equals(disableGroup)
					&& !account.equals(friendlist.get(position).friend)) {
				vh.friend.setText(friendlist.get(position).friend.substring(0,
						3)
						+ "*****"
						+ friendlist.get(position).friend.substring(
								friendlist.get(position).friend.length() - 3,
								friendlist.get(position).friend.length()));
			} else {
				vh.friend.setText(friendlist.get(position).friend);
			}

			vh.tv_teacher.setVisibility(View.INVISIBLE);
			if ("2".equals(friendlist.get(position).friend_type)) {
				vh.tv_teacher.setVisibility(View.VISIBLE);
				vh.tv_teacher.setText("Teacher");
			} else if ("0".equals(friendlist.get(position).friend_type)) {
				vh.tv_teacher.setVisibility(View.VISIBLE);
				vh.tv_teacher.setText("Student");
			} else if ("1".equals(friendlist.get(position).friend_type)) {
				vh.tv_teacher.setVisibility(View.VISIBLE);
				vh.tv_teacher.setText("Parent");
			} else if ("3".equals(friendlist.get(position).friend_type)) {
				vh.tv_teacher.setVisibility(View.VISIBLE);
				vh.tv_teacher.setText("Master");
			} else if (position >= 1 && position <= grouplist_count) {
				vh.tv_teacher.setVisibility(View.VISIBLE);
				vh.tv_teacher.setText("群");
			}
			// else
			// if(position==0&&"0".equals(mConversationListResq.friendList.get(position).ROLE)){
			// vh.tv_teacher.setVisibility(View.VISIBLE);
			// vh.tv_teacher.setText("Student");
			// }else
			// if(position==0&&"2".equals(mConversationListResq.friendList.get(position).ROLE)){
			// vh.tv_teacher.setVisibility(View.VISIBLE);
			// vh.tv_teacher.setText("Teacher");
			// }

			if ("".equals(friendlist.get(position).friend_headimg)) {
				Picasso.with(getActivity()).load(R.drawable.xuesheng).fit()
						.into(vh.iv_friend_headimg);

			} else {

				Picasso.with(getActivity())
						.load(friendlist.get(position).friend_headimg).fit()
						.into(vh.iv_friend_headimg);
			}

			return convertView;
		}

		class ViewHolder {
			private TextView friend_name;
			private TextView friend;
			private TextView tv_teacher;
			private ImageView iv_friend_headimg;
		}

		@Override
		public View getHeaderView(int position, View convertView,
				ViewGroup parent) {
			TextView tv = null;
			if (convertView == null || !(convertView instanceof TextView)) {
				tv = new TextView(getActivity());
			} else {
				tv = (TextView) convertView;
			}
			if (position == 0) {
				tv.setText("我自己");
			} else if (grouplist_count >= 1 && position >= 1
					&& position <= grouplist_count) {
				tv.setText("群聊");
			} else if (position > grouplist_count) {
				tv.setText("我的好友");
			}
			tv.setTextSize(14);
			tv.setPadding(10, 0, 10, 0);
			tv.setTextColor(0xcc000000);
			tv.setBackgroundColor(0xffE1E1E1);
			return tv;
		}

		@Override
		public long getHeaderId(int position) {

			if (position == 0) {
				return 0;
			} else if (grouplist_count >= 1 && position <= grouplist_count) {
				return 1;
			} else {
				return 2;
			}

		}
	}

	/**
	 * 设置 actionbar 事件
	 * 
	 * @param view
	 */
	private void setActionBarTitle(View view) {

		mTitle = (TextView) view.findViewById(R.id.tv_title);
		mBack = (RelativeLayout) view.findViewById(R.id.rl_back);

		mTitle.setText("我的伙伴");
		mBack.setVisibility(View.GONE);
		// mBack.setOnClickListener(new View.OnClickListener() {
		// @Override
		// public void onClick(View v) {
		// Toast.makeText(getActivity(), TAG, 0).show();
		// }
		// });

	}

	// 根据当前状态，调整header
	private void refreshHeaderViewByState() {
		switch (state) {
		case NONE:
			topPadding(-headerContentHeight);
			tip.setText(R.string.pull_to_refresh);
			refreshing.setVisibility(View.GONE);
			arrow.clearAnimation();
			arrow.setImageResource(R.drawable.pull_to_refresh_arrow);
			break;
		case PULL:

			arrow.setVisibility(View.VISIBLE);
			tip.setVisibility(View.VISIBLE);
			lastUpdate.setVisibility(View.VISIBLE);
			refreshing.setVisibility(View.GONE);
			tip.setText(R.string.pull_to_refresh);
			arrow.clearAnimation();
			arrow.setAnimation(reverseAnimation);
			// Toast.makeText(MainActivity.this, "", 0).show();
			break;
		case RELEASE:
			arrow.setVisibility(View.VISIBLE);
			tip.setVisibility(View.VISIBLE);
			lastUpdate.setVisibility(View.VISIBLE);
			refreshing.setVisibility(View.GONE);
			tip.setText(R.string.pull_to_refresh);
			tip.setText(R.string.release_to_refresh);
			arrow.clearAnimation();
			arrow.setAnimation(animation);
			break;
		case REFRESHING:
			topPadding(headerContentInitialHeight * 3 / 5);
			refreshing.setVisibility(View.VISIBLE);
			arrow.clearAnimation();
			arrow.setVisibility(View.GONE);
			tip.setVisibility(View.GONE);
			lastUpdate.setVisibility(View.GONE);
			break;
		}
	}

	// 调整header的大小。其实调整的只是距离顶部的高度。
	private void topPadding(int topPadding) {
		rl_lv_header
				.setPadding(rl_lv_header.getPaddingLeft(), topPadding,
						rl_lv_header.getPaddingRight(),
						rl_lv_header.getPaddingBottom());
		rl_lv_header.invalidate();
	}

	// 解读手势，刷新header状态
	private void whenMove(MotionEvent ev) {
		if (!isRecorded) {
			return;
		}
		int tmpY = (int) ev.getY();
		int space = tmpY - startY;
		int topPadding = space - headerContentHeight >= headerContentHeight ? headerContentHeight
				: space - headerContentHeight;
		switch (state) {
		case NONE:
			// Log.e("testtime", "NONE");
			if (space > 0) {

				state = PULL;
				refreshHeaderViewByState();
			}
			break;
		case PULL:
			// Log.e("testtime", "PULL");
			topPadding(topPadding);
			rl_lv_header.setVisibility(View.VISIBLE);
			if (space > headerContentHeight + SPACE) {
				state = RELEASE;
				refreshHeaderViewByState();
			}
			if (space > 0 && space < headerContentHeight + SPACE) {
				// Toast.makeText(getActivity(), "", 0).show();
				isRecorded = false;
				state = NONE;
				refreshHeaderViewByState();
				rl_lv_header.setVisibility(View.GONE);
			}

			break;
		case RELEASE:
			// topPadding(topPadding);
			// Log.e("testtime", "RELEASE");
			if (space > 0 && space < headerContentHeight + SPACE) {
				state = PULL;
				refreshHeaderViewByState();
			} else if (space <= 0) {
				state = NONE;
				refreshHeaderViewByState();
			}
			break;
		}

	}

	public void onRefreshComplete(String updateTime) {
		lastUpdate.setText(getActivity().getString(R.string.lastUpdateTime,
				Utils.getCurrentTime()));
		state = NONE;
		refreshHeaderViewByState();
	}

	// 用于下拉刷新结束后的回调
	public void onRefreshComplete() {
		String currentTime = Utils.getCurrentTime();
		onRefreshComplete(currentTime);
	}

	@Override
	public void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
		onRefreshComplete();
	}

	@Override
	public void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		// 设置箭头特效
		animation = new RotateAnimation(0, -180,
				RotateAnimation.RELATIVE_TO_SELF, 0.5f,
				RotateAnimation.RELATIVE_TO_SELF, 0.5f);
		animation.setInterpolator(new LinearInterpolator());
		animation.setDuration(500);
		animation.setFillAfter(true);

		reverseAnimation = new RotateAnimation(-180, 0,
				RotateAnimation.RELATIVE_TO_SELF, 0.5f,
				RotateAnimation.RELATIVE_TO_SELF, 0.5f);
		reverseAnimation.setInterpolator(new LinearInterpolator());
		reverseAnimation.setDuration(500);
		reverseAnimation.setFillAfter(true);

		lv_process_list.setOnTouchListener(new OnTouchListener() {

			@Override
			public boolean onTouch(View v, MotionEvent ev) {
				switch (ev.getAction()) {
				case MotionEvent.ACTION_DOWN:
					int firstVisiblePosition = lv_process_list
							.getFirstVisiblePosition();

					if (firstVisiblePosition == 0
							&& progressBar.getVisibility() == View.GONE) {
						isRecorded = true;
						startY = (int) ev.getY();
					}

					break;
				case MotionEvent.ACTION_MOVE:
					// if(state == REFRESHING){
					// isRecorded = false;
					// state = REFRESHING;
					// refreshHeaderViewByState();
					// }
					whenMove(ev);
					break;
				case MotionEvent.ACTION_UP:
					if (state == PULL) {
						state = NONE;
						refreshHeaderViewByState();
					} else if (state == RELEASE) {
						state = REFRESHING;
						refreshHeaderViewByState();

						// OkHttpClient mOkHttpClient = new OkHttpClient();
						// mOkHttpClient.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
						// FormEncodingBuilder builder = new
						// FormEncodingBuilder();
						// builder.add("userid",SPUtils.getString(getActivity(),
						// ConfigConstant.USERNAME));
						// builder.add("usertoken",
						// SPUtils.getString(getActivity(),
						// ConfigConstant.USERTOKEN));
						// Request request = new Request.Builder()
						// .url(path)
						// .post(builder.build()).build();
						// mOkHttpClient.newCall(request).enqueue(callBackFriendlist);

						new Handler().postDelayed(new Runnable() {

							@Override
							public void run() {
								// TODO Auto-generated method stub
								if (isRecorded) {
									isRecorded = false;
									state = NONE;
									refreshHeaderViewByState();
									rl_lv_header.setVisibility(View.GONE);
								}
							}
						}, 800);

					}
					break;
				}

				return false;
			}
		});

	}

}
